From f8308bc54345fe52ef3a24d98c4c38d92180662d Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 23 Feb 2015 00:06:12 +0100 Subject: [PATCH] Basic work for cargo install --- src/bin/cargo.rs | 1 + src/bin/install.rs | 89 ++++++++++++++++++++++++++++++++++ src/cargo/ops/cargo_install.rs | 17 +++++++ src/cargo/ops/mod.rs | 2 + tests/support/mod.rs | 1 + 5 files changed, 110 insertions(+) create mode 100644 src/bin/install.rs create mode 100644 src/cargo/ops/cargo_install.rs diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index bfa763852..11019d1ea 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -69,6 +69,7 @@ macro_rules! each_subcommand{ ($mac:ident) => ({ $mac!(generate_lockfile); $mac!(git_checkout); $mac!(help); + $mac!(install); $mac!(locate_project); $mac!(login); $mac!(new); diff --git a/src/bin/install.rs b/src/bin/install.rs new file mode 100644 index 000000000..8f443341b --- /dev/null +++ b/src/bin/install.rs @@ -0,0 +1,89 @@ +use cargo::ops; +use cargo::util::{CliResult, CliError, Config}; +use std::path::Path; + +#[allow(dead_code)] // for now until all options are implemented + +#[derive(RustcDecodable)] +struct Options { + flag_jobs: Option, + flag_features: Vec, + flag_no_default_features: bool, + flag_debug: bool, + flag_bin: Option, + flag_example: Vec, + flag_package: Vec, + flag_verbose: bool, + flag_root: Option, +} + +pub const USAGE: &'static str = " +Install a crate onto the local system + +Installing new crates: + cargo install [options] + cargo install [options] [-p CRATE | --package CRATE] [--vers VERS] + cargo install [options] --git URL [--branch BRANCH | --tag TAG | --rev SHA] + cargo install [options] --path PATH + +Managing installed crates: + cargo install [options] --list + +Options: + -h, --help Print this message + -j N, --jobs N The number of jobs to run in parallel + --features FEATURES Space-separated list of features to activate + --no-default-features Do not build the `default` feature + --debug Build in debug mode instead of release mode + --bin NAME Only install the binary NAME + --example EXAMPLE Install the example EXAMPLE instead of binaries + -p, --package CRATE Install this crate from crates.io or select the + package in a repository/path to install. + -v, --verbose Use verbose output + --root DIR Directory to install packages into + +This command manages Cargo's local set of install binary crates. Only packages +which have [[bin]] targets can be installed, and all binaries are installed into +`$HOME/.cargo/bin` by default (or `$CARGO_HOME/bin` if you change the home +directory). + +There are multiple methods of installing a new crate onto the system. The +`cargo install` command with no arguments will install the current crate (as +specifed by the current directory). Otherwise the `-p`, `--package`, `--git`, +and `--path` options all specify the source from which a crate is being +installed. The `-p` and `--package` options will download crates from crates.io. + +Crates from crates.io can optionally specify the version they wish to install +via the `--vers` flags, and similarly packages from git repositories can +optionally specify the branch, tag, or revision that should be installed. If a +crate has multiple binaries, the `--bin` argument can selectively install only +one of them, and if you'd rather install examples the `--example` argument can +be used as well. + +The `--list` option will list all installed packages (and their versions). +"; + +pub fn execute(options: Options, config: &Config) -> CliResult> { + config.shell().set_verbose(options.flag_verbose); + + let compile_opts = ops::CompileOptions { + config: config, + jobs: options.flag_jobs, + target: None, + features: &options.flag_features, + no_default_features: options.flag_no_default_features, + spec: None, + exec_engine: None, + mode: ops::CompileMode::Build, + release: true, + filter: ops::CompileFilter::Everything, + target_rustc_args: None, + }; + + let root = &Path::new("$HOME/.cargo/bin"); + + ops::install(&root, + &compile_opts).map_err(|err| { + CliError::from_boxed(err, 101) + }).map(|_| None) +} diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs new file mode 100644 index 000000000..2bd65cc0d --- /dev/null +++ b/src/cargo/ops/cargo_install.rs @@ -0,0 +1,17 @@ +use ops; +use util::CargoResult; +use sources::PathSource; +use std::path::Path; + +pub fn install(manifest_path: &Path, + opts: &ops::CompileOptions) -> CargoResult<()> { + let config = opts.config; + let src = try!(PathSource::for_path(manifest_path.parent().unwrap(), + config)); + let _root = try!(src.root_package()); + + println!("Compiling"); + try!(ops::compile(manifest_path, opts)); + + Ok(()) +} diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index f408b093a..5aa156cd6 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -7,6 +7,7 @@ pub use self::cargo_rustc::{Context, LayoutProxy}; pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig}; pub use self::cargo_rustc::{CommandType, CommandPrototype, ExecEngine, ProcessEngine}; pub use self::cargo_run::run; +pub use self::cargo_install::install; pub use self::cargo_new::{new, NewOptions, VersionControl}; pub use self::cargo_doc::{doc, DocOptions}; pub use self::cargo_generate_lockfile::{generate_lockfile}; @@ -28,6 +29,7 @@ mod cargo_compile; mod cargo_doc; mod cargo_fetch; mod cargo_generate_lockfile; +mod cargo_install; mod cargo_new; mod cargo_package; mod cargo_pkgid; diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 38e434870..90b1dfac8 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -563,3 +563,4 @@ pub static DOWNLOADING: &'static str = " Downloading"; pub static UPLOADING: &'static str = " Uploading"; pub static VERIFYING: &'static str = " Verifying"; pub static ARCHIVING: &'static str = " Archiving"; +pub static INSTALLED: &'static str = " Installed"; -- 2.30.2